package com.easico.adapter;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.easico.activity.FragmentContent;

import java.util.ArrayList;
import java.util.List;

/**
 * 初始化顶部菜单项目
 */
public class AppSectionsPagerAdapter extends FragmentStateAdapter {
    private final List<Fragment> fragments;
    private final List<String> fragmentTitles;

    public AppSectionsPagerAdapter(FragmentActivity fa) {
        super(fa);
        fragments = new ArrayList<>();
        fragmentTitles = new ArrayList<>();

        // 添加fragments和标题
        fragments.add(new FragmentContent());
        fragments.add(new FragmentContent());
        fragments.add(new FragmentContent());

        fragmentTitles.add("电子帐簿");
        fragmentTitles.add("易购");
        fragmentTitles.add("电子扫面");
    }

    @Override
    public Fragment createFragment(int position) {
        return fragments.get(position);
    }

    @Override
    public int getItemCount() {
        return fragments.size();
    }

    public String getPageTitle(int position) {
        return fragmentTitles.get(position);
    }
}